#include "TIL.h"


TIL::TIL()
{
	m_File = new FileHandler();
}


TIL::~TIL()
{
	
}

void TIL::Load( char* a_FilePath )
{
	m_File->LoadFile( a_FilePath, "rb" );

	m_File->ReadInt( &m_Width );
	m_File->ReadInt( &m_Height );
	
	for ( int i = 0; i < m_Width; i++ )
	{
		for ( int j = 0; j < m_Height; j++ )
		{
			m_File->ReadByte( &m_Tiles[i][j].m_BrushID );
			m_File->ReadByte( &m_Tiles[i][j].m_TileIndex );
			m_File->ReadByte( &m_Tiles[i][j].m_TileSet );
			m_File->ReadInt( &m_Tiles[i][j].m_TileID );
		}
	}

	m_File->Close();
}

void TIL::Save( char* a_FilePath )
{
	m_File->LoadFile( a_FilePath, "wb" );

	m_File->WriteInt( &m_Width );
	m_File->WriteInt( &m_Height );

	for ( int i = 0; i < m_Width; i++ )
	{
		for ( int j = 0; j < m_Height; j++ )
		{
			m_File->WriteByte( &m_Tiles[i][j].m_BrushID );
			m_File->WriteByte( &m_Tiles[i][j].m_TileIndex );
			m_File->WriteByte( &m_Tiles[i][j].m_TileSet );
			m_File->WriteInt( &m_Tiles[i][j].m_TileID );
		}
	}
	
	m_File->Close();
}

Tile TIL::GetTile( unsigned int a_X, unsigned int a_Y )
{
	return m_Tiles[a_X][a_Y];
}
